package com.ggboy.item_bank.controller;

import com.ggboy.item_bank.beans.Specialty;
import com.ggboy.item_bank.beans.Subject;
import com.ggboy.item_bank.beans.User;
import com.ggboy.item_bank.service.SpecialtyService;
import com.ggboy.item_bank.service.SubjectService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class PageController {

    @Resource
    private SpecialtyService specialtyService;

    @Resource
    private SubjectService subjectService;

    @RequestMapping("/")//跳转到登录页
    public String login() {
        return "login";
    }

    @RequestMapping("/register")
    public String register(Model model) {
        List<Specialty> list = specialtyService.listSpecialty();//查出所有的学院以供选择
        model.addAttribute("Specialties", list);//用model保存
        return "register";
    }

    @RequestMapping("/toCapacity")//智能组卷走的方法
    public String toCapacity(Model model, HttpSession session) {
        User user = (User) session.getAttribute("user");//登录时存入的用户信息
        String teacherSpecialty = user.getTeacherSpecialty();//取出你的学院信息
        int i = Integer.parseInt(teacherSpecialty);//字符串转为int
        List<Subject> subjectList = subjectService.selectSubBySpecialtyId(i);//查询出这个学院的所有课程
        model.addAttribute("subjectList", subjectList);//用model存起来
        return "capacityPaper";
    }
}
